package com.sikaryofficial.system.api.factory;

import com.sikaryofficial.common.core.domain.R;
import com.sikaryofficial.system.api.RemoteFileService;
import com.sikaryofficial.system.api.domain.SysFile;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.cloud.openfeign.FallbackFactory;
import org.springframework.stereotype.Component;
import org.springframework.web.multipart.MultipartFile;

/**
 * 文件服务降级处理
 *
 * @author qinjinyuan
 */
@Component
public class RemoteFileFallbackFactory implements FallbackFactory<RemoteFileService> {
    private static final Logger log = LoggerFactory.getLogger(RemoteFileFallbackFactory.class);

    @Override
    public RemoteFileService create(Throwable throwable) {
        log.error("文件服务调用失败:{}", throwable.getMessage());
        return new RemoteFileService() {
            @Override
            public R<SysFile> upload(MultipartFile file) {
                return R.fail("Upload Fail:" + throwable.getMessage());
            }

            /**
             * 视频上传文件
             *
             * @param file 文件信息
             * @return 结果
             */
            @Override
            public R<SysFile> uploadVideo(MultipartFile file) {
                return R.fail("Upload Video Fail:" + throwable.getMessage());
            }

            /**
             * 音视频合成
             *
             * @param file           文件信息
             * @param audioPath
             * @param audioStartTime
             * @param audioDuration
             * @return 结果
             */
            @Override
            public R<SysFile> mergeAudioAndVideo(MultipartFile file, String audioPath, String audioStartTime, String audioDuration,
                                                 String videoCoverUrl) {
                return R.fail("Merge Fail:" + throwable.getMessage());
            }

            /**
             * 音频上传文件
             *
             * @param file 文件信息
             * @return 结果
             */
            @Override
            public R<SysFile> uploadAudio(MultipartFile file) {
                return R.fail("Upload Audio Fail:" + throwable.getMessage());
            }
        };
    }
}
